from PySide6.QtCore import QDateTime, Slot, Qt
from PySide6.QtWidgets import QMessageBox, QDialog, QTableWidgetItem, QMainWindow, QButtonGroup
from PySide6.QtGui import QIcon, QColor

from Devices.Chiot.BsDevs.ComDev.Forms.ComDevWindow import ComDevWindow
from Devices.Chiot.BsDevs.Humiture.HumitureDevice import HumitureDevice
from Devices.Chiot.BsDevs.Humiture.HumitureParser import HumitureParser
from Devices.Chiot.BsDevs.Humiture.Forms.HumitureWindow_UI import Ui_FormHumitureWindow
from Components.MessageBoxFunc import MessageBoxFunc

class HumitureWindow(ComDevWindow):
    # 0、窗体初始化、状态变量初始化
    def __init__(self, supportDevice, parent = None):
        # 注意在实现特有设备时，一定要先将其ui对象加载完毕
        super().__init__(supportDevice, parent)

        self.FullStatus = HumitureDevice.HumitureFullStatus()

        self._ui = Ui_FormHumitureWindow()
        self._ui.setupUi(self)
        self.initUiWindow()
        self.SetupUi(self._ui)
        # self.testUi()

    # 1、数据解析
    def setHeartbeatStatus(self):
        pass

    def CmdRptStatusReceived(self, msgValue):
        if HumitureParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdHeartbeatReceived(self, msgValue):
        if HumitureParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdFullStatusReceived(self, msgValue):
        if HumitureParser.ParseHeartbeat(msgValue, self.FullStatus):
            self.setFullStatus()

    def CmdMsgValueReceived(self, msgName, msgValue):
        pass

    # 2、运行状态
    def setFullStatus(self):                          
        self._ui.label_temperature.setText(str(self.FullStatus.temperature))
        self._ui.label_humidity.setText(str(self.FullStatus.humidity))
        # self._ui.label_batteryPercentage.setText(str(self.FullStatus.batteryPercentage) + "%")
        # self._ui.label_checkStatus.setText("正在自检" if self.FullStatus.checkStatus else "未自检")
      